home *** CD-ROM | disk | FTP | other *** search
- /*
- Filename Wallpaper.c
- Copyright © 1993 David Hart. All rights reserved.
- Author David Hart
- Description (Windows) Wallpaper module for After Dark
-
- Version Date Comments
- 2.00 23/03/93 Original Version for After Dark 2.0
- 2.01 26/03/93 To use the pict rect to get the width & height
- */
-
- #include <QuickDraw.h>
- #include <Memory.h>
- #include <OSUtils.h>
- #include "GraphicsModule_Types.h"
-
- #define PICTID 128 /* ID of first PICT */
- #define NUMPICTS 8 /* number of PICTS in resource */
-
- /* Function prototypes */
- int Rand(int range);
-
- /* Specific graphics module data structures */
- typedef struct MyStorage
- {
- int monitor;
- int h;
- int v;
- int width;
- int height;
- int pictNum;
- } MyStorage, *MyStoragePtr, **MyStorageHandle;
-
- /*
- DoInitialize is the first function called from After Dark.
- Memory for the structure is allocated and the variables are initialized.
- The allocated memory is assigned to "storage"
- and the function returns "noErr" if there are no problems.
- */
- OSErr DoInitialize(Handle *storage, RgnHandle blankRgn, GMParamBlockPtr params)
- {
- MyStorageHandle myStorage;
- int pictNum;
-
- /* allocate handle to my storage */
- myStorage = (MyStorageHandle)NewHandle(sizeof(MyStorage));
-
- if (!myStorage)
- return MemError();
-
- MoveHHi(myStorage);
- HLock(myStorage); /* Lock it down */
-
- *storage = (Handle)myStorage; /* Assign myStorage to passed handle */
-
- (**myStorage).monitor = 0;
- (**myStorage).h = 0;
- (**myStorage).v = 0;
- (**myStorage).pictNum = Rand(NUMPICTS) + PICTID;
- HUnlock(myStorage);
- return noErr;
- }
-
- /*
- DoBlank is the next function called.
- It is used to simply blank the screen.
- */
- OSErr DoBlank(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params)
- {
- FillRgn(blankRgn, params->qdGlobalsCopy->qdBlack);
- return noErr;
- }
-
- /*
- DoDrawFrame does almost all of the work.
- */
- OSErr DoDrawFrame(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params)
- {
- OSErr err = noErr;
- MyStoragePtr myStorage; /* to hold dereferenced storage handle */
- Rect pictRect;
- Rect rect;
- PicHandle pict;
- int nextPict;
-
- /* Lock our storage down so we can dereference it once for faster access */
- MoveHHi(storage);
- HLock(storage);
- myStorage = (MyStoragePtr)*storage;
-
- /* Get the PICT resource, draw it and replease it */
- pict = GetPicture(myStorage->pictNum);
- myStorage->width = (**pict).picFrame.right - (**pict).picFrame.left;
- myStorage->height = (**pict).picFrame.bottom - (**pict).picFrame.top;
- SetRect(&pictRect, myStorage->h, myStorage->v, myStorage->h+myStorage->width, myStorage->v+myStorage->height);
- DrawPicture(pict, &pictRect);
- ReleaseResource(pict);
-
- rect = params->monitors->monitorList[myStorage->monitor].bounds;
-
- /* Next vertical position */
- myStorage->v += myStorage->height;
- if (myStorage->v >= rect.bottom)
- {
- /* Off the bottom, reset to top and try next horizontal */
- myStorage->v = rect.top;
-
- /* Next horizontal position */
- myStorage->h += myStorage->width;
- if (myStorage->h >= rect.right)
- {
- /* Off the right, reset to left and try next monitor */
- myStorage->h = rect.left;
-
- /* Next monitor */
- myStorage->monitor++;
- if (myStorage->monitor >= params->monitors->monitorCount)
- {
- /* All monitors done, try another pict */
- myStorage->monitor = 0;
-
- /* Another pict at random */
- nextPict = Rand(NUMPICTS) + PICTID;
- if (nextPict == myStorage->pictNum)
- {
- /* Same as last one so use the 'next' one */
- nextPict++;
- if (nextPict >= NUMPICTS + PICTID)
- nextPict = PICTID;
- }
- myStorage->pictNum = nextPict;
- }
-
- /* Monitor bounds rect */
- rect = params->monitors->monitorList[myStorage->monitor].bounds;
- myStorage->h = rect.left;
- myStorage->v = rect.top;
- }
- }
-
- HUnlock(storage);
- return noErr;
- }
-
- /*
- DoClose is called when the user quits the screen saver.
- The memory is deallocated and the function returns "MemError"
- which will tell After Dark if there was a problem
- */
- OSErr DoClose(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params)
- {
- MyStorageHandle myStorage = (MyStorageHandle)storage;
- int pictNum;
-
- /* Deallocate our storage */
- if (myStorage)
- {
- MoveHHi(myStorage);
- HLock(myStorage);
-
- DisposHandle(storage);
- }
-
- /* check for memory errors */
- return MemError();
- }
-
- /*
- DoSetUp is called if the user clicks on a button in the Control Panel.
- */
- OSErr DoSetUp(RgnHandle blankRgn, short message, GMParamBlockPtr params)
- {
- return noErr;
- }
-
- /*
- Rand returns value (0..range-1)
- */
- int Rand(int range)
- {
- long result = Random();
-
- if (result < 0)
- result =- result;
-
- return ((result * range) / 32768);
- }
-